﻿using System;
using System.Collections.Generic;

using UnityEngine;

using BaseLib;

namespace ScriptProject
{
    public class TestCoroutine
    {
        public static void RunTest()
        {
            CoroutineDemo.Instance.DoCoroutine(Coroutine());

            CoroutineDemo.Instance.DoCoroutine2(Coroutine2());
            CoroutineDemo.Instance.DoCoroutine2(Coroutine3());
        }

        static bool s_flag = false;

        static System.Collections.IEnumerator Coroutine2()
        {
            yield return CoroutineMgr.Instance.WaitTime(1.0f);
            Debug.Log("111");
            yield return CoroutineMgr.Instance.WaitUntil(() => s_flag);
            Debug.Log("Flag is:" + s_flag);
        }

        static System.Collections.IEnumerator Coroutine3()
        {
            yield return CoroutineMgr.Instance.WaitTime(2.0f);
            s_flag = true;
        }

        static System.Collections.IEnumerator Coroutine()
        {
            Debug.Log("开始协程,t=" + Time.time);
            yield return new WaitForSeconds(3);
            Debug.Log("等待了3秒,t=" + Time.time);
        }
    }
}
